function [plabel, acc, decv] = libsvmpredict_f(lbl, data, model, settings, ind)
dataname = [settings.title,'_',num2str(ind),'.predict'];
if ~isfield(model, 'file')
    error('Cannot find model file');
end
libsvmwrite(dataname, lbl, sparse(data));
modelname = model.file;
outputname = [settings.title,'_',num2str(ind),'.output'];

[M,N] = size(lbl);
if (N~=1) || (M<=0)
    error([num2str(ind),'Size of lbl must be M*1, M > 0']);
end
%% call svmpredict
cmd = [settings.svmpredict,' ',settings.predict_opt,' ',dataname,' ',modelname,' ',outputname];
if settings.verbose >= 2
    disp(cmd);
end
[e, w] = system(cmd);
if settings.verbose >= 1
    disp(w)
end
if e ~= 0
    error([num2str(ind),': Execution failed with error code: ',num2str(e)]);
end
delete(dataname);
%% parse output
fid = fopen(outputname, 'rt');
if (fid == -1)
    error([num2str(ind),': Cannot read predict output ',outputname]);
end
plabel = zeros(M,1);
for i = 1:M
    s = fgetl(fid);
    if ~ischar(s)
        warning([num2str(ind),': Reached EOF before filled matrix.']);
        break
    end
    plabel(i) = str2num(s);
end
fclose(fid);
delete(outputname);
acc = sum(lbl == plabel) / M;
decv = [];
end